/*
 * CopiadoImagenesDemonio.java
 *
 * Created on 19 de septiembre de 2007, 04:25 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package com.computec.core.imagenes.demonio;

import com.computec.core.imagenes.base.constantes.ConstantesGenerales;
import com.computec.core.imagenes.base.helper.BaseHelper;
import com.computec.core.imagenes.dao.BaseImagenesDAO;
import com.src.computec.radar.base.dao.exception.DAOException;
import java.util.Calendar;
import java.util.List;

/**
 *
 * @author jlperea
 */
public class CopiadoImagenesDemonio extends BaseHelper implements Runnable
{
    BaseImagenesDAO dao = null;
    ConstantesGenerales constantes = null;
    
    /** Creates a new instance of CopiadoImagenesDemonio */
    public CopiadoImagenesDemonio() 
    {
        System.out.println("CopiadoImagenesDemonio: CopiadoImagenesDemonio: ");    
        dao = (BaseImagenesDAO) this.getFactoryDAO().getImagenesDAO();
        constantes = ConstantesGenerales.getInstance();
    }
    
    public void run() 
    {
        while(true)
        {            
            try
            {                
                if(puedeEjecutar())
                {
                    dao.procesarBloqueCopiadoImagenes();
                    System.out.println("CopiadoImagenesDemonio: ejecuto Copiado dao.procesarBloqueCopiadoImagenes(): " + new java.util.Date());                     
                }
                System.out.println("CopiadoImagenesDemonio: run: SLEEP");
                Thread.sleep(constantes.SLEEP_TIME);  
            } 
            catch(DAOException e)
            {
                System.out.println("CopiadoImagenesDemonio: run: DAOException: " + e.toString()); 
                e.printStackTrace();
            }
            catch (InterruptedException e) 
            {
                System.out.println("CopiadoImagenesDemonio: run: InterruptedException: " + e.toString()); 
                e.printStackTrace();
            }
            catch (Exception e) 
            {
                System.out.println("CopiadoImagenesDemonio: run: Exception: " + e.toString()); 
                e.printStackTrace();
            }
        } 
    }
    
    public boolean puedeEjecutar()
    {
        Calendar calendar = Calendar.getInstance();        
        if( calendar.get(Calendar.HOUR_OF_DAY) >= constantes.HOUR_RANGE_FROM && calendar.get(Calendar.HOUR_OF_DAY) <= constantes.HOUR_RANGE_TO )
        {
            return true;
        }
        return false;
    }
}
